<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <div class="app-space-between">
        <div class="app-space-between-left">
          <el-form-item label="运费模板名称:" prop="freight">
            <el-input v-model="queryParams.freight" placeholder="请输入运费模板名称" clearable @clear="handleQuery"
              @keyup.enter.native="handleQuery" />
          </el-form-item>
        </div>
        <div class="app-space-between-right">
          <el-form-item>
            <el-button type="primary" size="mini" @click="handleQuery">搜索</el-button>
            <el-button size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </div>
      </div>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="handleAdd">新增运费模板</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
      <el-table-column show-overflow-tooltip type="selection" width="55" align="center" />
      <el-table-column show-overflow-tooltip label="运费模板名称" width="300" align="center" prop="templateName" />
      <el-table-column show-overflow-tooltip label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          {{scope.row.creatorTime | $YYYY_MM_DD_hh_mm_ss}}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="操作" align="center" width="140" fixed="right">
        <template slot-scope="scope">
          <el-link type="primary" @click="handleUpdate(scope.row)" :underline="false">编辑</el-link>
          <el-link type="primary" @click="handleDelete(scope.row)" :underline="false" style="margin:0 6px;">删除
          </el-link>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 增 改 -->
    <deliveryAdd ref="delivery-add"></deliveryAdd>
  </div>
</template>

<script>
  import {
    listWcSubDeliveryTemplate,
    deletewcSubDeliveryTemplate,
  } from "@/api/culturalCreativity/delivery.js";
  import deliveryAdd from "./components/delivery-add.vue";
  export default {
    components: {
      deliveryAdd,
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 岗位表格数据
        postList: [],
        // 弹出层标题
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          freight: ""
        },
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询岗位列表 */
      getList() {
        this.loading = true;
        listWcSubDeliveryTemplate(this.queryParams).then(response => {
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.configId)
        this.single = selection.length != 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs['delivery-add'].init();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        let postId = row.postId || this.ids
        if (Array.isArray(postId)) postId = postId.toString();
        this.$refs['delivery-add'].init(postId);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        let postIds = row.configId || this.ids;
        if (Array.isArray(postIds)) postIds = postIds.toString()
        this.$modal.confirm('此操作将要删除所选的数据，是否继续？').then(function() {
          return deletewcSubDeliveryTemplate(postIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      }
    }
  };
</script>
